package com.example.datedemo2.controller;

import com.example.datedemo2.domain.WeekSample;
import com.example.datedemo2.service.WeekSampleService;
import com.example.datedemo2.service.dto.ResponseResult;
import com.example.datedemo2.service.dto.weekSample.WeekSampleAddDto;
import com.example.datedemo2.service.dto.weekSample.WeekSampleUpdateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api("周相关")
@RestController
public class WeekSampleController {
    @Resource
    private WeekSampleService weekSampleService;

    @ApiOperation(value = "显示全部周")
    @GetMapping("/week/allWeek")
    public List<WeekSample> getAll() {
        return weekSampleService.selectAll();
    }

    @ApiOperation(value = "根据主键id显示Week")
    @GetMapping("/week/getWeekById/{id}")
    public ResponseResult getById(@PathVariable("id") String id) {
        return weekSampleService.selectById(id);
    }

    @ApiOperation(value = "根据projectId,monthParameter,weekParameter显示week")
    @GetMapping("/week/getWeekByWeekNumber/{projectId}/{monthParameter}/{weekParameter}")
    public ResponseResult getByWeekParameter(@PathVariable("projectId") int projectId, @PathVariable("monthParameter") String monthParameter, @PathVariable("weekParameter") int weekParameter) {
        return weekSampleService.selectByWeekParameter(projectId, monthParameter, weekParameter);
    }

    @ApiOperation(value = "<内部调用，外部请勿调用> 根据项目id和月份显示Week：请使用2015-2或2015-02格式")
    @GetMapping("/week/getWeekByMonth/{projectId}/{month}")
    public List<WeekSample> getByIdByMonth(@PathVariable("projectId") int projectId, @PathVariable String month) {
        return weekSampleService.selectByWeekRange(projectId, month);
    }

    @ApiOperation(value = "新增一个Week")
    @PostMapping("/week/insertWeek")
    public ResponseResult insertWeekSample(@RequestBody WeekSampleAddDto weekSampleAddDto) {
        return weekSampleService.insertWeekSample(weekSampleAddDto);
    }

    @ApiOperation(value = "更新指定Week")
    @PutMapping("/week/updateWeek")
    public ResponseResult updateWeekSample(@RequestBody WeekSampleUpdateDto weekSampleUpdateDto) {
        return weekSampleService.updateWeekSample(weekSampleUpdateDto);
    }

    @ApiOperation(value = "根据主键id删除Week")
    @DeleteMapping("/week/deleteWeekById/{id}")
    public ResponseResult deleteWeekSampleById(@PathVariable String id) {
        return weekSampleService.deleteWeekSampleById(id);
    }
}
